<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>offsetTop</title>
    <style>
        body{
            margin: 0;
        }
        #box1{
            width: 100px;
            height: 100px;
            background-color: yellowgreen;
            margin-left: 100px;

        }
        #box2 {
            width: 100px;
            height: 100px;
            background-color: yellow;
            margin-top: 50px;
        }
    </style>
</head>
<body>
<div style="margin: 100px;position: relative">
    <div id="box1"></div>
    <div id="box2"></div>
</div>

        <script>
            var s =document.getElementById('box1');
            var z = document.getElementById('box2');
            console.log(z.offsetTop);     // z 距离他父级元素向上的高度是150；前提是定位过
            console.log(z.offsetLeft);     //z 距离他父级元素向左的距离是0；
        </script>
</body>
</html>